package com.example.cunion.controller;

import com.example.cunion.common.R;
import com.example.cunion.controller.form.PageFom;
import com.example.cunion.entity.RotationChart;
import com.example.cunion.service.RotationChartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/rotation")
public class RotationChartController {

    @Resource
    private RotationChartService rotationChartService;

    @GetMapping("/searchAllRotationChart")
    public R searchAllRotationChart(@RequestHeader("token") String token){
        ArrayList<HashMap> list = rotationChartService.searchAllRotationChart();
        return R.ok().put("result", list);
    }

    @PostMapping("/addRotationChartByMp")
    public R addRotationChartByMp(@RequestHeader("token") String token, @RequestBody RotationChart rotationChart) {
        rotationChartService.addRotationChartByMp(rotationChart);
        return R.ok();
    }

    @GetMapping("/deleteRotationChartByMp")
    public R deleteRotationChartByMp(@RequestHeader("token") String token, @RequestParam("rotationChartId") String rotationChartId) {
        rotationChartService.deletedRotationChartByMp(rotationChartId);
        return R.ok();
    }
    @PostMapping("/updateRotationChartByMp")
    public R updateRotationChartByMp(@RequestHeader("token") String token, @RequestBody RotationChart rotationChart) {
        rotationChartService.updateRotationChartByMp(rotationChart);
        return R.ok();
    }
    @PostMapping("/searchRotationChartByMp")
    public R searchRotationChartByMp(@RequestHeader("token") String token, @RequestBody PageFom form){
        List<RotationChart> list = rotationChartService.searchRotationChartByMp(form.getStart(), form.getLength());
        return R.ok().put("result", list);
    }
}
